/**
 * Created by liangf on 17/08/11.
 */
import Cookies from 'js-cookie';

 /* 字符串转数字 */
export function strParseInt(strn) {
  const I = parseInt(strn);
  if (I === 'NaN') {
    return strn;
  }
  return I;
}
  /* 获取按钮功能权限 */
export function btnIsVisible(SoleCode) {
  const permissionSoleCodes = eval(Cookies.get('ownership'));
  return permissionSoleCodes.indexOf(SoleCode) > 0
}

// 获取URL参数
export function getUrlParams(requestParams) {
  // const getParams = new URLSearchParams();
  let getParams = '?operatorid=' + Cookies.get('uid') + '&lastlogincode=' + Cookies.get('lastlogincode');
  for (const obj in requestParams) {
    if (requestParams[obj] && obj !== 'currentPage' && obj !== 'pageSize' && obj !== 'operatorid') {
      // getParams.append(obj, requestParams[obj]);
      getParams += '&' + obj + '=' + requestParams[obj]
      // console.log(getParams);
    }
  }
  return getParams
}

// 去掉字符串首尾空格
export function trimStr(str) {
  if (str) {
    return str.replace(/(^\s*)|(\s*$)/g, '')
  }
}